﻿#region <!-- Using Directives -->

using System;
using System.IO;

using WordSharpDev.Extensions;

#endregion

namespace WordSharpDev.Properties
{
	internal partial class Resources
	{
		#region <!-- GetDocument -->

		public static String GetDocument(String p_Name)
		{
			String l_Name = null;
			Byte[] l_Data = null;

			if (p_Name.IsLikeFull("WordSharpProject")) { l_Name = "WordSharpProject.mdf"; l_Data = Resources.db_EmptyDatabase; }

			if (p_Name.IsLikeFull("BaseDocument")) { l_Name = "BaseDocument.docx"; l_Data = Resources.doc_BaseDocument; }

			if (p_Name.IsLikeFull("SampleBasicMaths")) { l_Name = "SampleBasicMaths.docx"; l_Data = Resources.doc_SampleBasicMaths; }

			if (l_Name == null) return null;
			if (l_Data == null) return null;

			l_Name = Path.Combine(Root.TempDirectory.FullName, l_Name);

			if (!l_Name.AsFile().Exists)
			{
				using (var l_Stream = new FileStream(l_Name, FileMode.Create))
				{
					l_Stream.Write(l_Data, 0, l_Data.Length);

					l_Stream.Flush(true);
				}
			}

			return l_Name;
		}

		#endregion
	}
}